home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / PartMaker 4.4 / PartMaker Documents / Script Runner• / Script Runner•.rsrc / dFRK_5025 < prev    next >
Encoding:
Text File  |  1995-12-12  |  3.5 KB  |  173 lines

  1. /*------------------------------------------------------------------------------
  2.     File:        OSAPlugIn.cpp
  3.     
  4.     Contains:    OSAPlugIn class implementation
  5.     
  6.     Written by:    Sue Dumont
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. ------------------------------------------------------------------------------*/
  10.  
  11. // -- Compiler/Preprocessor Notification --
  12.  
  13. #ifndef _COMPILERDEFS_
  14. #include "CompDefs.h"
  15. #endif
  16.  
  17. // -- OpenDoc Utilities --
  18.  
  19. #ifndef _EXCEPT_
  20. // Exceptions define several important macros (eg. CHECKENV)
  21. // which are used in the SOM method dispatch glue. If Except.h
  22. // is not included early enough, exceptions may not be thrown
  23. // correctly when returning from a SOM method with the "ev" parameter set.
  24. #include <Except.h>
  25. #endif
  26.  
  27. // -- OSAPlugIn Includes --
  28.  
  29. #ifndef SOM_Sample_ScriptRunnerAgent_xh
  30. #include "ScriptRunnerAgent.xh"
  31. #endif
  32.  
  33. #ifndef _OSAPLUGINDEF_
  34. #include "OSAPlugInDef.h"
  35. #endif
  36.  
  37. // -- OpenDoc Includes --
  38.  
  39. #ifndef _ODTYPES_
  40. #include <ODTypes.h>
  41. #endif
  42.  
  43. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  44. #include <StdTypes.xh>
  45. #endif
  46.  
  47. #ifndef _SHPLUGIN_
  48. #include <ShPlugIn.h>
  49. #endif
  50.  
  51. #ifndef SOM_M_ODObject_xh
  52. #include <ODObject.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODObjectNameSpace_xh
  56. #include <ObjectNS.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODNameSpaceManager_xh
  60. #include <NmSpcMg.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODDraft_xh
  64. #include <Draft.xh>
  65. #endif
  66.  
  67. #ifndef SOM_ODDocument_xh
  68. #include <Document.xh>
  69. #endif
  70.  
  71. #ifndef SOM_ODContainer_xh
  72. #include <ODCtr.xh>
  73. #endif
  74.  
  75. #ifndef SOM_ODStorageSystem_xh
  76. #include <ODStor.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODStorageUnit_xh
  80. #include <StorageU.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODSession_xh
  84. #include <ODSessn.xh>
  85. #endif
  86.  
  87. // -- OpenDoc Utilities --
  88.  
  89. #ifndef _ODNEW_
  90. #include <ODNew.h>
  91. #endif
  92.  
  93. #ifndef _ODUTILS_
  94. #include <ODUtils.h>
  95. #endif
  96.  
  97. // -- Macintosh Includes --
  98.  
  99. #ifndef __APPLESCRIPT__
  100. #include <AppleScript.h>
  101. #endif
  102.  
  103. #ifndef __GESTALT__
  104. #include <Gestalt.h>
  105. #endif
  106.  
  107.  
  108. #ifdef __cplusplus
  109. extern "C" {
  110. #endif
  111.  
  112. // The pragma exports are needed for Symantec projects.
  113. #pragma export on    
  114. OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft, ODShellPlugInActionCodes* action);
  115. #pragma export off
  116.  
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120.  
  121.  
  122. #pragma segment ScriptRunnerAgent
  123.  
  124. //------------------------------------------------------------------------------
  125. // Method:        Install
  126. //
  127. // Description:    Instantiate the ScriptRunnerAgent object and register it
  128. //                into the Object Name Space.
  129. //------------------------------------------------------------------------------
  130.  
  131. OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft,
  132.                             ODShellPlugInActionCodes* action )
  133. {
  134.     ODNameSpaceManager*                nameSpMgr;
  135.     ODNameSpace*                    objNameSpace;
  136.     ODSLong                            value;
  137.     Sample_ScriptRunnerAgent*        agent = kODNULL;
  138.     OSErr                            err = noErr;
  139.     
  140.     ODVolatile(agent);
  141.  
  142.     SOM_TRY
  143.         // First check to see if AppleScript is present. Only
  144.         // if it is present do we proceed.
  145.         err = Gestalt(gestaltAppleScriptAttr, &value);
  146.     
  147.         if ( !err && (value & (1<<gestaltAppleScriptPresent)) )
  148.         {
  149.             nameSpMgr = ODGetSession(ev, draft)->GetNameSpaceManager(ev);
  150.         
  151.             objNameSpace = nameSpMgr->HasNameSpace(ev, kOSAScriptingTool);
  152.             
  153.             if ( objNameSpace == kODNULL )
  154.             {
  155.                 objNameSpace = nameSpMgr->CreateNameSpace(ev, kOSAScriptingTool,
  156.                                                 kODNULL, (ODULong)1, kODNSDataTypeODObject);
  157.         
  158.                 agent = new Sample_ScriptRunnerAgent;
  159.                 THROW_IF_NULL(agent);
  160.                     
  161.                 ((ODObjectNameSpace*)objNameSpace)->Register(ev, kOSAScriptingTool, agent);
  162.             }
  163.         }        
  164.     
  165.         *action = kODShellPlugInNoAction;
  166.     
  167.     SOM_CATCH_ALL
  168.         err = ErrorCode();
  169.     SOM_ENDTRY
  170.     
  171.     return err;
  172. }
  173.